home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part2 / 15905 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  2.5 KB

  1. Path: news.sprintlink.net!datalytics!usenet
  2. From: Rob Stewart <stew@datalytics.com>
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: What are the differences between structures and classes in C++ ?
  5. Date: Mon, 08 Apr 1996 15:44:54 -0400
  6. Organization: Datalytics, Inc
  7. Message-ID: <31696CB6.79C3@datalytics.com>
  8. References: <4k9cr3$fl9@arl-news-svc-5.compuserve.com>
  9. NNTP-Posting-Host: 204.62.224.71
  10. Mime-Version: 1.0
  11. Content-Type: text/plain; charset=iso-8859-1
  12. Content-Transfer-Encoding: quoted-printable
  13. X-Mailer: Mozilla 2.0 (WinNT; I)
  14.  
  15. Philippe Verdy wrote:
  16. > =
  17.  
  18. > marnold@netcom.com (Matt Arnold) s'=E9crit :
  19. > > Raghuveera Ravinutala <raghur> writes:
  20. > >
  21. > > ><jtbell@presby.edu (Jon Bell)> wrote :
  22. > > >>the only *formal* difference between a class and a
  23. > > >>struct is that by default, class members are private whereas struct
  24. > > >>members are public.
  25. > >[snip]
  26. > > In other words, structs *are* classes.
  27. > =
  28.  
  29. > And so, the "class" keyword was not necessary to C++ !!! It is
  30. > for only an historical (and cultural) reason that classes in C
  31. > can be specified with the "class" keyword. Historically,
  32. > structs in first C++ beta versions did not allow for methods
  33. > and constructor (because classes complicated the C++ to C
  34. > conversion, and made compilation time and generated volume
  35. > of C source much bigger). However, the need of costructors
  36. > for PODS structs relaxed this rule, and structs gained all
  37. > the capabilities of classes, for clarity and simplicity !
  38. > =
  39.  
  40.  
  41. Historical significance in beta versions of C++ translators, =
  42.  
  43. aside, the reason for the class keyword is to make private =
  44.  
  45. access the default.  It is a way to highlight that you should =
  46.  
  47. hide as much as you can.
  48.  
  49. > In most sources,
  50. > the public members are specified at the beginning of the class
  51. > definition so using "struct" instead of "class" avoids to
  52. > explicitly use the "public:" access modifier and saves 7
  53. > characters !!!
  54. > =
  55.  
  56.  
  57. While this is accurate, and indeed there is no significant =
  58.  
  59. difference between structs and classes, I prefer to use class =
  60.  
  61. and struct to indicate something more.  class refers to =
  62.  
  63. something that hides information and provides a strictly defined =
  64.  
  65. interface.  struct refers to something that makes no attempt to =
  66.  
  67. hide its representation, though it may have ctors, dtors, and =
  68.  
  69. other mfs.
  70.  
  71. In other words, while I can declare protected and private access =
  72.  
  73. sections in a struct, I don't.  I leave structs entirely public, =
  74.  
  75. preferring class for everything else.  This clarifies my intent.
  76.  
  77. -- =
  78.  
  79. Robert Stewart        | My opinions are usually my own.
  80. Datalytics, Inc.    | stew@datalytics.com
  81.